package cn.tedu.egnotice0806.controller;

import cn.tedu.egnotice0806.base.response.JsonResult;
import cn.tedu.egnotice0806.mapper.NoticeMapper;
import cn.tedu.egnotice0806.pojo.dto.NoticeAddParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
@Slf4j
@RestController
@RequestMapping("/v1/notice/")
public class NoticeController {

    @Autowired
    private NoticeMapper noticeMapper;

    @Operation(summary = "01.添加资讯", description = "添加资讯的API接口")
    @ApiOperationSupport(order = 10)
    @Parameters({
            @Parameter(name = "title", description = "标题", required = true, example = "xxx"),
            @Parameter(name = "content", description = "内容"),
            @Parameter(name = "type"),
            @Parameter(name = "status"),
            @Parameter(name = "userId"),
    })
    @PostMapping(value = "add", produces = "application/json")
    public JsonResult addNotice(NoticeAddParam noticeAddParam) {
        noticeAddParam.setCreateTime(new Date());
        noticeAddParam.setUpdateTime(new Date());
        log.debug("noticeAddParam: {}", noticeAddParam);
        noticeMapper.addNotice(noticeAddParam);
        return JsonResult.ok();
    }
}
